package com.wva.common.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * 能够安全地在父子线程、线程池传递的认证上下文
 * @Author: hong
 * @Date: 2025/2/12 22:04:34
 */
public class UserContext {
    /**
     * 用户id
     */
    private static final TransmittableThreadLocal<Long> userId = new TransmittableThreadLocal<>();

    public static long getUserId() {
        return userId.get();
    }

    public static void setUserId(long val) {
        userId.set(val);
    }
    public static boolean isLogin() {
        return userId.get() != null;
    }

    public static void clear() {
        userId.remove();
    }
}
